<template>
    <div style="width: 100%;height: 500px;" class="echarts-box" ref="chart"></div>
</template>

<script>
    import api from '../network/api/APIecharts.js'
    export default {
        name: 'profit_line',

        data() {
            return {

            };
        },

        mounted() {
            this.initEchart();
        },

        methods: {
            initEchart() {
                let myChart = this.$echarts.init(this.$refs.chart);
                let data_x=[];
                let data_y=[];
                // 绘制图表

                //折线图数据
                api.getProfit().then(res=>{
                    console.log(res.data);
                    for(var i=res.data.length-1;i>=0;i--){
                        data_x.push(res.data[i].today);
                        data_y.push(res.data[i].today_sales_money);
                    }

                    myChart.setOption({
                    color:"#E94136",

                    xAxis: {
                        name: '日期',
                        type: 'category',
                        data: data_x
                    },
                    yAxis: {
                        name: '元',
                        type: 'value'
                    },
                    tooltip: {
                        trigger: 'axis'  //鼠标悬浮显示信息
                    },
                    series: [
                        {
                            data: data_y,
                            type: 'line',
                            smooth: true
                        }
                    ]

                });
                })

            }
        },
    };
</script>

<style lang="scss" scoped>

</style>